# -*- coding:utf-8 -*-

import smtplib
from email.mime.text import MIMEText
from email.header import Header


# 第三方 SMTP 服务
mail_host = "smtp.163.com"  # 设置服务器
mail_user = "koala_sea"  # 用户名
mail_port = 25  # 端口
mail_pass = "UMEJQLHEVKQWDVPE"  # 口令

sender = 'koala_sea@163.com'  # 设置发件邮箱
receivers = ['9826468@qq.com']  # 接收邮件邮箱


subject = 'Python SMTP 邮件'  # 主题

for r in receivers:
    message = MIMEText('Python 发送内容', 'plain', 'utf-8')  # 发送内容
    message['From'] = sender  # Header("koala_sea@163.com", 'utf-8')  # 发送人信息
    message['To'] = r  # 收件人信息
    message['Subject'] = Header(subject, 'utf-8')
    try:
        smtpObj = smtplib.SMTP()
        smtpObj.connect(mail_host, mail_port)    # 25 为 SMTP 端口号
        smtpObj.login(mail_user, mail_pass)
        smtpObj.sendmail(sender, receivers, message.as_string())
        print ("邮件发送成功")
    # except smtplib.SMTPException:
    except Exception as e:
        print ("Error: 无法发送邮件")